package site.yunnong.atvris.portal.spider.baidu;

import org.springframework.stereotype.Service;
import site.yunnong.atvris.dao.domain.Video;
import site.yunnong.atvris.dao.mapper.VideoMapper;
import site.yunnong.atvris.portal.spider.AbstractVideoObject;
import site.yunnong.atvris.portal.spider.VideoImportService;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author zjh
 * @date 2021/8/31 14:43
 */
@Service
public class BaiduVideoImportServiceImpl implements VideoImportService {
    
    @Resource
    private VideoMapper videoMapper;

    @Override
    public void importVideo(AbstractVideoObject videoObject) {
        System.out.println("insert video, video.title: " + ((BaiduVideo) videoObject).getVideoTitle());
        Video video = Video.builder().uuid(SYS_UID)
                .userAvatar(SYS_USER_AVATAR)
                .userNickname(SYS_USER_NICKNAME)
                .pid(DEFAULT_PID)
                .partitionName(DEFAULT_PARTITION_NAME)
                .level(0)
                .status(1)
                .cover(((BaiduVideo) videoObject).getImgUrl())
                .videoTime(0L)
                .url(((BaiduVideo) videoObject).getHref())
                .seriesNum(1)
                .title(((BaiduVideo) videoObject).getVideoTitle())
                .rePrintPower(1)
                .fromUrl(((BaiduVideo) videoObject).getSource())
                .remark(((BaiduVideo) videoObject).getRemark())
                .uploadTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build();
        videoMapper.insertSelective(video);
        System.out.println("insert video, video.title: " + ((BaiduVideo) videoObject).getVideoTitle() + "SUCCESS");
    }
}
